package ch.sv7.tool.dbmanager.db.fixbuilder;

import ch.sv7.tool.dbmanager.Context;
import ch.sv7.tool.dbmanager.db.ForeignKeySchema;
import ch.sv7.tool.dbmanager.db.dialect.Dialect;
import ch.sv7.tool.dbmanager.db.difference.MissingTableDifference;
import ch.sv7.tool.dbmanager.db.difference.SchemaDifference;
import ch.sv7.tool.dbmanager.db.fix.CreateForeignKeyFix;
import ch.sv7.tool.dbmanager.db.fix.CreateTableFix;
import ch.sv7.tool.dbmanager.db.fix.SchemaFix;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class MissingTableFixBuilder implements FixBuilder {

	public SchemaFix[] createFixes(SchemaDifference difference, Dialect dialect, Context context) {
		MissingTableDifference missingTableDifference = (MissingTableDifference)difference;
		SchemaFix[] fixes = new SchemaFix[missingTableDifference.getExpectedTableSchema().getForeignKeys().size() + 1]; 
		fixes[0] = new CreateTableFix(missingTableDifference.getExpectedTableSchema());
		for (int i=0; i<missingTableDifference.getExpectedTableSchema().getForeignKeys().size(); i++) {
			ForeignKeySchema fk = (ForeignKeySchema)missingTableDifference.getExpectedTableSchema().getForeignKeys().get(i);
			fixes[i + 1] = new CreateForeignKeyFix(fk);
		}
		return fixes;
	}

}
